package com.bcu.calculus.utils;

import com.bcu.calculus.entity.Act;
import com.bcu.calculus.entity.ActNumber;
import com.bcu.calculus.entity.Semester;
import com.bcu.calculus.entity.SemesterNumber;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SemesterUtil {

    public static Semester change(SemesterNumber semesterNumber) throws ParseException {
        Semester semester = new Semester();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        if (semesterNumber.getSemId() != null) {
            semester.setSemId(semesterNumber.getSemId());
        }

        if (semesterNumber.getSemName() != null) {
            semester.setSemName(semesterNumber.getSemName());
        }

        if (semesterNumber.getSemStatus() != null) {
            semester.setSemStatus(semesterNumber.getSemStatus());
        }

        try {
            if (semesterNumber.getSemCheckStartTime() != null) {
                Date Time = formatter.parse(semesterNumber.getSemCheckStartTime());
                semester.setSemCheckStartTime(Time);
            }
        } catch (Exception e) {
            semester.setSemCheckStartTime(null);
        }

        try {
            if (semesterNumber.getSemCheckStopTime() != null) {
                Date Time = formatter.parse(semesterNumber.getSemCheckStopTime());
                semester.setSemCheckStopTime(Time);
            }
        } catch (Exception e) {
            semester.setSemCheckStopTime(null);
        }

        try {
            if (semesterNumber.getSemSendStartTime() != null) {
                Date Time = formatter.parse(semesterNumber.getSemSendStartTime());
                semester.setSemSendStartTime(Time);
            }
        } catch (Exception e) {
            semester.setSemSendStartTime(null);
        }

        try {
            if (semesterNumber.getSemSendStopTime() != null) {
                Date Time = formatter.parse(semesterNumber.getSemSendStopTime());
                semester.setSemSendStopTime(Time);
            }
        } catch (Exception e) {
            semester.setSemSendStopTime(null);
        }
        return semester;
    }
}
